package com.bdweb.controller;

import com.bdweb.pojo.Result;

import com.bdweb.service.impl.MedailServiceImpl;

import com.bdweb.service.impl.PowerAllServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class SwitchAllController {
    @Autowired
    private PowerAllServiceImpl powerAllService;
    @Autowired
    private MedailServiceImpl medailServiceImpl;



    @CrossOrigin("*") //添加跨越访问。
    @GetMapping("/switchAll")

    public Result switchAll(int id) throws IOException, InterruptedException {
        if(id==0){
            powerAllService.listPowerOpenAll();
            Thread.sleep(10000);
            medailServiceImpl.listMedailOpenAll();
        }
        if(id==1){
            medailServiceImpl.listMedailCloseAll();
            Thread.sleep(10000);
            powerAllService.listPowerCloseAll();

        }

        return new Result(200, "success", id==0?"设备全部开启OK":"设备全部关闭OK");
    }
}
